package com.hfut.eeg.service;

import com.hfut.eeg.dao.EerWavesMapper;
import com.hfut.eeg.dto.EEGReq;
import com.hfut.eeg.dto.PatientListResult;
import com.hfut.eeg.dto.EerWaves;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author 梁琦
 * @program: eeg
 * @Package com.hfut.eeg.service
 * @Description: TODO
 * @date 2019-12-11 09:37
 */
@Service
@Scope("singleton")
public class EerWavesService {

    @Autowired
    private EerWavesMapper eerWavesMapper;

    @Autowired
    private PatientInfoService patientInfoService;

    /**
    * 插入异常波数据
    */
    public int insertEerWaves(List<EerWaves> list){
        int i= -1;
        try{
            if(list!=null && list.size()!=0){
                i =eerWavesMapper.insertEerWaves(list);
            }else {
                i=1;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return i;
    }

    /**
    * 获取异常波数据
    */
    public HashMap<String,Object> getEerWaves(EEGReq energy){
        if(energy==null){
            return null;
        }
        HashMap<String,Object> req = new HashMap<>();
        String patientId = energy.getPatientId();
        req.put("patientId",patientId);
        req.put("startWaves",(energy.getOrder()-1)*500*10);
        req.put("endWaves",(energy.getNum()+energy.getOrder()-1)*500*10);
        PatientListResult patientListResult= patientInfoService.getPatientById(patientId);
        List<EerWaves> list=eerWavesMapper.getEerWaves(req);
        HashMap<String,Object>map = new HashMap<>();
        map.put("time",patientListResult.getCheckTime());
        map.put("errWaves",list);
        return map;
    }

    /**
    * 获取所有异常波数据
    */
    public HashMap<String,Object> getAllEerWaves(String patientId){
        if(patientId==null || "".equals(patientId)){
            return null;
        }
        PatientListResult patientListResult= patientInfoService.getPatientById(patientId);
        List<EerWaves> list=eerWavesMapper.getAllEerWaves(patientId);
        HashMap<String,Object>map = new HashMap<>();
        map.put("time",patientListResult.getCheckTime());
        map.put("errWaves",list);
        return map;
    }


}
